package com.itheima.reggie.mapper;

import com.itheima.reggie.dto.SetmealDto;
import com.itheima.reggie.entity.Setmeal;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetmealMapper {

    @Select("select count(*) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(String categoryId);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into setmeal (`category_id`, `name`, `price`, `status`, `code`, `description`, `image`, `create_time`, `update_time`, `create_user`, `update_user`) values (#{categoryId},#{name},#{price},#{status},#{code},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insert(SetmealDto setmealDto);

    @Select("select *,c.name as categoryName from setmeal as s,category as c where s.category_id = c.id and s.name like concat(\"%\",ifnull(#{name},\"\"),\"%\")")
    List<SetmealDto> selectAllByName(String name);

    @Delete("delete from setmeal where id = #{id}")
    void delete(String id);

    @Update("update setmeal set status = #{status} where id = #{id}")
    void updateStatus(String id, int status);

    @Select("select status from setmeal where id = #{id}")
    Integer selectStatusById(String id);

    @Select("select * from setmeal where id = #{id}")
    SetmealDto selectAllById(String id);


    //修改 setmeal 表中 name,price,category_id,image,description,update_time,update_user属性
    @Update("update setmeal set name = #{name},category_id = #{categoryId},price = #{price},image = #{image},description = #{description},update_time = #{updateTime},update_user = #{updateUser} where id = #{id}")
    void updateById(SetmealDto setmealDto);

    @Select("select * from setmeal where category_id = #{categoryId}")
    List<Setmeal> selectByCategoryId(String categoryId);
}
